var InterValObj;//变量控制时间
var count= 60;//间隔函数，1秒执行
var curCount;//当前剩余秒数
//发送验证码
function sendMessage(){
    curCount=count;
    document.getElementById("yzm").setAttribute("disabled","true");
    document.getElementById("yzm").value=curCount + "秒后重获";
    InterValObj=window.setInterval(SetRemainTime,1000);
}
function SetRemainTime() {
if (curCount==0){
    window.clearInterval(InterValObj);
    document.getElementById("yzm").removeAttribute("disabled");
    document.getElementById("yzm").value="重获验证码";
}else {
    curCount--;
    document.getElementById("yzm").value=curCount + "秒后重获";
}
}
function foLogin() {
    //定义变量
    var u_name = document.getElementById('name');
    var uError = document.getElementById('error_box');
    var uError2 = document.getElementById('error_box2');
    var uError3 = document.getElementById('error_box3');
    var uError4 = document.getElementById('error_box4');
    var uError5 = document.getElementById('error_box5');
    var u_pwd = document.getElementById('upwd');
    var u_pwd2 = document.getElementById('upwd2');
    var u_email = document.getElementById('email');
    var inputCode = document.getElementById('u_code');
    var isError = true;
    uError.innerHTML = "";
    uError2.innerHTML = "";
    uError3.innerHTML = "";
    uError4.innerHTML = "";

    //对用户名进行判断

    if (u_name.value.length < 6 || u_name.value.length > 20 || u_name.value == '') {
        uError.innerHTML = '请输入6-20位的用户名';
        isError = false;
        return isError;
    } else if (u_name.value.charCodeAt(0) >= 48 && (u_name.value.charCodeAt(0) <= 57)) {
        uError.innerHTML = "用户名首位不能为数字";
        return isError;
    }
    //对用户输入的密码进行判断

    if (u_pwd.value.length < 6 || u_pwd.value.length > 16 || u_pwd.value == '') {
        uError2.innerHTML = "请输入6-16位的密码";
        isError = false;
        return isError;
    } else if (u_pwd.value != u_pwd2.value) {
        uError3.innerHTML = "两次密码不一致，请重新输入！";
        isError = false;
        return isError;
        //邮箱判断
    }
    // if (u_email.value == '') {
    //     uError4.innerHTML = "请输入用户邮箱";
    //     isoError = false;
    //     return;
    // }
    // //验证码判断
    // if (inputCode.value.toUpperCase() != code || inputCode.value == '') {
    //     uError5.innerHTML = "验证码错误，请正确输入验证码！";
    //     isError = false;
    //     return;
    //
    // } else {
    //     uError5.innerHTML = "";
    //     setTimeout(function () { window.open("../html/enter.html") }, 1000);
    //     alert("登录完成！点击跳转到登录页面...");
    //     isError = true;
    //     return;
    //
    // }

}
//=========获取表单数据=============
function getFormData() {
  var formData = {};
  // var salt ="spring";
  // var newPassword = $.md5($("#upwd").val()+ salt); // 前端密码加密
  // console.log("md5 new pwd:" + newPassword)
  //
  // $("#upwd").val(newPassword);
  // $("#upwd2").val(newPassword);
  var PUBLIC_KEY = '';


    $.ajax({
      type: "GET",
      url: "../publickey",
      dataType: 'json',
      success: function (result) {
        PUBLIC_KEY = result.data; //获得公钥

        var encrypt = new JSEncrypt();
        // encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');

        encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');

        var password = $("#upwd").val();

        var encrypted = encrypt.encrypt(password);

        console.log('前端  0公钥：%o',PUBLIC_KEY);
        console.log('加密后的数据：%o', encrypted);

        $("#upwd").val(encrypted);
        $("#upwd2").val(encrypted);

        console.log("密码。。。。。：%o" + $("#upwd").val());

        $("#form").submit();

      }
    })






}
